<?php

declare(strict_types=1);
/**
 * This file is part of MoChat.
 * @link     https://mo.chat
 * @document https://mochat.wiki
 * @contact  group@mo.chat
 * @license  https://github.com/mochat-cloud/mochat/blob/master/LICENSE
 */
namespace MoChat\Plugin\ContactTrack\Action\Dashboard;

use Hyperf\Di\Annotation\Inject;
use Hyperf\HttpServer\Annotation\Controller;
use Hyperf\HttpServer\Annotation\Middleware;
use Hyperf\HttpServer\Annotation\Middlewares;
use Hyperf\HttpServer\Annotation\RequestMapping;
use MoChat\App\Common\Middleware\DashboardAuthMiddleware;
use MoChat\App\Rbac\Middleware\PermissionMiddleware;
use MoChat\App\WorkEmployee\Contract\WorkEmployeeContract;
use MoChat\Framework\Action\AbstractAction;
use MoChat\Framework\Request\ValidateSceneTrait;
use MoChat\Plugin\ContactFollow\Contract\ContactFollowContract;
use MoChat\Plugin\ContactTrack\Contract\ContactTrackContract;

/**
 * 互动轨迹-事件.
 *
 * Class EventIndex
 * @Controller
 */
class EventIndex extends AbstractAction
{
    use ValidateSceneTrait;

    /**
     * 互动轨迹表.
     * @Inject
     * @var ContactTrackContract
     */
    private $track;

    /**
     * @Inject
     * @var ContactFollowContract
     */
    private $contactFollowService;

    /**
     * @Inject
     * @var WorkEmployeeContract
     */
    private $workEmployeeService;

    /**
     * @Middlewares({
     *     @Middleware(DashboardAuthMiddleware::class),
     *     @Middleware(PermissionMiddleware::class)
     * })
     * @RequestMapping(path="/dashboard/contactTrack/eventIndex", methods="GET")
     */
    public function handle()
    {
    }

    /**
     * @return string[] 规则
     */
    public function rules(): array
    {
        return [
            'contactId' => 'required|integer|min:1|bail',
        ];
    }

    /**
     * 获取已定义验证规则的错误消息.
     */
    public function messages(): array
    {
        return [
            'contactId.required' => '客户id必传',
        ];
    }

    protected function getWeek($date)
    {
        // 强制转换日期格式
        $date_str = date('Y-m-d', strtotime($date));

        // 封装成数组
        $arr = explode('-', $date_str);

        // 参数赋值
        // 年
        $year = $arr[0];

        // 月，输出2位整型，不够2位右对齐
        $month = sprintf('%02d', $arr[1]);

        // 日，输出2位整型，不够2位右对齐
        $day = sprintf('%02d', $arr[2]);

        // 时分秒默认赋值为0；
        $hour = $minute = $second = 0;

        // 转换成时间戳
        $strap = mktime($hour, $minute, $second, (int) $month, (int) $day, (int) $year);

        // 获取数字型星期几
        $number_wk = date('w', $strap);

        // 自定义星期数组
        $weekArr = ['星期日', '星期一', '星期二', '星期三', '星期四', '星期五', '星期六'];

        // 获取数字对应的星期
        return $weekArr[$number_wk];
    }
}
